from sqlalchemy import Column, INTEGER
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy_dm import VARCHAR2, NUMBER, TIMESTAMP

# 创建对象的基类
Base = declarative_base()

# 生成结果历史类
class CompanyScore(Base):
    # 模式名
    __table_args__ = {'schema': 'ESUNTEST'}
    # 表名
    __tablename__ = 'HX_BI_QYPJ'
    # 表结构
    ID = Column(INTEGER, primary_key=True, autoincrement=True)
    PJZW = Column(VARCHAR2(256))
    PJSJ = Column(TIMESTAMP)
    PJGSID = Column(VARCHAR2(100))
    PJGS = Column(VARCHAR2(256))
    ZQXYDJ = Column(VARCHAR2(100))
    PJGSJC = Column(VARCHAR2(256))
    ZTDJ = Column(VARCHAR2(256))
    GSMC = Column(VARCHAR2(256))
    PCH = Column(VARCHAR2(256))
    SCORE = Column(NUMBER)

    @classmethod
    def from_dict(cls, data):
        return cls(
            ID=int(data.get('ID')) if data.get('ID') is not None else 0,
            PJZW=data.get('PJZW'),
            PJSJ=data.get('PJSJ'),
            PJGS=data.get('PJGS'),
            ZQXYDJ=data.get('ZQXYDJ'),
            PJGSJC=data.get('PJGSJC'),
            ZTDJ=data.get('ZTDJ'),
            GSMC=data.get('GSMC'),
            PCH=data.get('PCH'),
            SCORE=data.get('SCORE')
        )

    def to_dict(self):
        return {
            'ID': self.ID,
            'PJZW': self.PJZW,
            'PJSJ': self.PJSJ,
            'PJGS': self.PJGS,
            'ZQXYDJ': self.ZQXYDJ,
            'PJGSJC': self.PJGSJC,
            'ZTDJ': self.ZTDJ,
            'GSMC': self.GSMC,
            'PCH': self.PCH,
            'SCORE': self.SCORE
        }
